package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.KeywordData;
import com.cskaoyan.bean.MarketKeyword;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.service.KeywordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Kongwo
 * @description
 * @since 2022/05/06 20:00
 */

@RestController
@RequestMapping("admin/keyword")
public class KeywordController {

    @Autowired
    KeywordService keywordService;

    @GetMapping("list")
    public BaseRespVo keywordList(String keyword, String url, BaseParam param) {

        KeywordData keywordData = keywordService.getKeywordList(keyword, url, param);
        return BaseRespVo.ok(keywordData);
    }

    @GetMapping("read")
    public BaseRespVo keywordRead() {
        return null;
    }

    @PostMapping("create")
    public BaseRespVo keywordCreate(@RequestBody MarketKeyword marketKeyword) {

        MarketKeyword newKeyword = keywordService.addNewKeyword(marketKeyword);
        return BaseRespVo.ok(newKeyword);
    }

    @PostMapping("update")
    public BaseRespVo keywordUpdate(@RequestBody MarketKeyword marketKeyword) {

        MarketKeyword newKeyword = keywordService.updateKeyword(marketKeyword);
        return BaseRespVo.ok(newKeyword);
    }

    @PostMapping("delete")
    public BaseRespVo keywordDelete(@RequestBody MarketKeyword marketKeyword) {

        keywordService.deleteKeyword(marketKeyword.getId());
        return BaseRespVo.ok(null);
    }
}
